package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result selectEmp(EmpQueryParam empQueryParam){
        PageResult<Emp> pageResult = empService.selectEmp(empQueryParam);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result savaEmp(@RequestBody Emp emp){
        empService.savaEmp(emp);
        return Result.success();
    }

    //删除
    @DeleteMapping
    public Result deleteEmp(@RequestParam List<Integer> ids){
        empService.deleteEmp(ids);
        return Result.success();
    }

    //回显员工信息和员工工作经历
    @GetMapping("{id}")
    public Result getEmp(@PathVariable Integer id){
//        Emp emp = empService.getEmpWithExprById(id);
        Emp emp = empService.getEmpById(id);
        return Result.success(emp);
    }

    //修改员工信息和员工工作经历
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        empService.updateEmp(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result findAll(){
        List<Emp> empList = empService.list();
        return Result.success(empList);
    }
}
